package com.ht.impl.shape;

import com.htgraph.contour.ContourResult;
import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.model.mxCell;
import com.mxgraph.shape.mxBasicShape;
import com.mxgraph.view.mxCellState;

import java.awt.geom.Rectangle2D;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2010-6-23
 */
public class htContourShape extends mxBasicShape {
    public void paintShape(mxGraphics2DCanvas canvas, mxCellState state) {
        long start = System.currentTimeMillis();
        mxCell cell = (mxCell) state.getCell();
        ContourResult value = (ContourResult) cell.getValue();
        double w = state.getWidth() / value.getXgrids();
        double h = state.getHeight() / value.getYgrids();
        double x = state.getX();
        double y = state.getY();
        for (int num : value.getGridValues().keySet()) {
            canvas.getGraphics().setColor(value.getColorMaker().createColor(value.getGridValues().get(num)));
            int[] ij = value.getIJ(num);
            canvas.getGraphics().fill(new Rectangle2D.Double(x + ij[1] * w - 1, y + ij[0] * h - 1, w + 2, h + 2));
            //canvas.getGraphics().draw(new Rectangle2D.Double(x + ij[1] * w, y + ij[0] * h, w, h));
        }
        System.out.println("Time used for painting contour: " + (System.currentTimeMillis() - start) + "ms");
    }
}
